package com.inspur.web.controller.system;

import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.core.page.TableDataInfo;
import com.inspur.common.enums.BusinessType;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.system.dto.PmWorkItemDTO;
import com.inspur.system.service.IPmWorkItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【工作项】Controller
 * 
 * @author ruoyi
 * @date 2024-04-09
 */
@RestController
@RequestMapping("/system/workItem")
public class PmWorkItemController extends BaseController
{
    @Autowired
    private IPmWorkItemService pmWorkItemService;

    /**
     * 查询【工作项】列表
     */
    @PreAuthorize("@ss.hasPermi('system:workItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(PmWorkItemDTO pmworkItem)
    {
        startPage();
        List<PmWorkItemDTO> list = pmWorkItemService.selectPmworkItemList(pmworkItem);
        return getDataTable(list);
    }

    /**
     * 查询工作项数量
     */
    @PreAuthorize("@ss.hasPermi('system:workItem:listnum')")
    @GetMapping("/listNum")
    public AjaxResult listNum(PmWorkItemDTO pmworkItem)
    {
        return success(pmWorkItemService.selectPmworkItemNum(pmworkItem));
    }

    /**
     * 导出【工作项】列表
     */
    @PreAuthorize("@ss.hasPermi('system:workItem:export')")
    @Log(title = "【导出工作项列表】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmWorkItemDTO pmworkItem)
    {
        List<PmWorkItemDTO> list = pmWorkItemService.selectPmworkItemList(pmworkItem);
        ExcelUtil<PmWorkItemDTO> util = new ExcelUtil<PmWorkItemDTO>(PmWorkItemDTO.class);
        util.exportExcel(response, list, "导出数据");
    }

    /**
     * 获取【工作项】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:workItem:query')")
    @GetMapping(value = "/{cPmNo}")
    public AjaxResult getInfo(@PathVariable("cPmNo") Long cPmNo)
    {
        return success(pmWorkItemService.selectPmworkItemByCPmNo(cPmNo));
    }

    /**
     * 关联【工作项】
     */
    @PreAuthorize("@ss.hasPermi('system:workItem:demwork')")
    @Log(title = "关联工作项", businessType = BusinessType.DELETE)
    @PostMapping("/demWork")
    public AjaxResult demWork(@RequestParam("cPmNo") String cPmNo, @RequestParam("cWork") String cWork)
    {
        return toAjax(pmWorkItemService.demPmworkItemByCPmNos(cPmNo,cWork));
    }

    /**
     * 删除【工作项】
     */
    @PreAuthorize("@ss.hasPermi('system:workItem:remove')")
    @Log(title = "删除工作项", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cPmNos}")
    public AjaxResult remove(@PathVariable Long[] cPmNos)
    {
        return toAjax(pmWorkItemService.deletePmworkItemByCPmNos(cPmNos));
    }
}
